Microsoft DirectX 8.1 (C++)

Setting and Retrieving the Stream Position

The filter graph maintains two position values: the current position and the stop position:

To retrieve the current position, call the IMediaSeeking::GetCurrentPosition method. To retrieve the stop position, call the IMediaSeeking::GetStopPosition method. The returned values are in units of the current time format (see preceding section). They are always relative to the original media source.

To seek to a new position, or to set a new stop position, call the IMediaSeeking::SetPositions method. The following code shows an example:

#define ONE_SECOND 10000000
REFERENCE_TIME rtNow = 2 * ONE_SECOND, rtStop = 5 * ONE_SECOND;

hr = pSeek->SetPositions(
    &rtNow,  AM_SEEKING_AbsolutePositioning, 
    &rtStop, AM_SEEKING_AbsolutePositioning
    );

This example assumes that the current time format is media time, which has units of 100 nanoseconds. One second is 10,000,000 units. For convenience, the example defines this value as ONE_SECOND.

Note   If you are using the DirectShow base classes, the base-class library defines the constant UNITS, which has the same value. For more information, see DirectShow Base Classes.

The rtNow parameter specifies the new position. The second parameter is a flag that defines how to interpret rtNow. The flag in this example indicates that rtNow is defined as an absolute position in the source. When the call returns, the filter graph seeks to a position that is two seconds from the start of the stream. The rtStop parameter gives the stop time. The last parameter is another flag, indicating that the stop time is also an absolute position.

To specify a position relative to the previous position value, use the AM_SEEKING_RelativePositioning flag. To leave one of the position values unchanged, use the AM_SEEKING_NoPositioning flag. The corresponding time parameter can be NULL in that case. The following example seeks forward by 10 seconds, leaving the stop position unchanged:

REFERENCE_TIME rtNow = 10 * ONE_SECOND;
hr = pSeek->SetPositions(
    &rtNow, AM_SEEKING_RelativePositioning, 
    NULL, AM_SEEKING_NoPositioning
    );

When the filter graph is stopped, the video renderer does not update its image after a seek operation. To the user, it will appear as if the seek did not happen. To update the image, pause the graph after the seek operation. Pausing the graph cues a new video frame for the video renderer. The IMediaControl::StopWhenReady method pauses the graph and then returns it to a stopped state.